using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using DG.Tweening;

public class Light
{
    private List<LightItem> _lightItems;

    public Light(Transform root)
    {
        _lightItems = new List<LightItem>();
        for (int i = 0; i < root.childCount; i++)
        {
            var item = new LightItem(root.GetChild(i).gameObject);
            _lightItems.Add(item);
        }
    }

    public void NormalSplash()
    {
        for (int i = 0; i < _lightItems.Count; i++)
        {
            _lightItems[i].Off();
        }
        for (int i = 0; i < _lightItems.Count; i++)
        {
            if (i % 2 == 0)
            {
                _lightItems[i].Splash(0);
            }
            else
            {
                _lightItems[i].Splash(.5f);
            }
        }
    }

    public void RotateSplash()
    {
        for (int i = 0; i < _lightItems.Count; i++)
        {
            _lightItems[i].On();
        }
    }

    public void EndSplash()
    {
        for (int i = 0; i < _lightItems.Count; i++)
        {
            _lightItems[i].Off();
        }
        for (int i = 0; i < _lightItems.Count; i++)
        {
            _lightItems[i].Splash(0);
        }
    }
}

public class LightItem
{
    public Image on;

    public LightItem(GameObject item)
    {
        on = item.transform.GetChild(1).GetComponent<Image>();
    }

    public void Splash(float dely)
    {
        on.DOFade(1, .5f).SetLoops(-1, LoopType.Yoyo)
            .SetDelay(dely);
    }

    public void Off()
    {
        on.DOKill();
        on.DOFade(0, 0f);
    }

    public void On()
    {
        on.DOKill();
        on.DOFade(1, 0f);
    }
}
